﻿using BootstrapBlazor.Components;
using Furion.EventBus;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;
using System.Diagnostics.CodeAnalysis;

namespace OnWork.DataCenter.Shared.Pages.Common
{
    /// <summary>
    ///  组件继承类
    /// </summary>
    public class ComponentBaseDataCenter : ComponentBase
    {
        /// <summary>
        /// 页面名称
        /// </summary>
        protected virtual string PageName { get; set; }

        [Inject]
        [NotNull]
        protected ToastService? ToastService { get; set; }

        [Inject]
        [NotNull]
        protected DialogService? DialogService { get; set; }

        /// <summary>
        /// 消息设置
        /// </summary>
        [Inject]
        [NotNull]
        private MessageService? MessageService { get; set; }

        /// <summary>
        /// 日志组件
        /// </summary>
        [Inject]
        [NotNull]
        private ILogger<ComponentBaseDataCenter> Logger { get; set; }

        #region Table默认配置

        /// <summary>
        /// 分页的选项
        /// </summary>
        protected static IEnumerable<int> PageItems
        {
            get
            {
                return new int[] { 20, 40, 60 };
            }
        }

        #endregion Table默认配置

        /// <summary>
        /// 显示消息信息
        /// </summary>
        protected async Task<bool> ShowSqlReturnMsg(BLL.Base.Dto.SQLReturn sqlReturn)
        {
            //成功
            if (sqlReturn.IsSuccess)
            {
                await ToastService?.Success(sqlReturn.Title, sqlReturn.Content);
            }
            else //失败
            {
                await ToastService?.Error(sqlReturn.Title, sqlReturn.Content);
            }
            return sqlReturn.IsSuccess;
        }

        /// <summary>
        ///  显示错误信息
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        protected async Task MessageError(string msg)
        {
            Logger.LogError(msg);
            await MessageService.Show(new MessageOption()
            {
                Content = msg,
                Icon = "fa-solid fa-circle-info",
                Color = Color.Danger,
                ShowDismiss = true,
                ShowBar = true,
            });
        }
    }
}